package cn.myfirefly.moming.common.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import cn.myfirefly.moming.common.dao.mapper.DepartmentMapper;
import cn.myfirefly.moming.common.entity.MMDepartment;
import cn.myfirefly.moming.common.entity.MMDepartmentStaff;
import cn.myfirefly.core.BaseDao;
import cn.myfirefly.utils.CollectionUtil;

@Repository
public class DepartmentStaffDao extends BaseDao<MMDepartmentStaff>{
	
	@Autowired
	private DepartmentMapper departmentMapper;
	
	public void delByStaffSn(Integer staffSn) {
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery(" delete from MMDepartmentStaff where staffSn = ? " );
		query.setInteger(0, staffSn);
		query.executeUpdate();
	}
	
	public MMDepartment getDepartment(Integer staffSn) {
		List<MMDepartment> list = departmentMapper.getDeptByStaffSn(staffSn);
		if (CollectionUtil.isNotEmpty(list)) {
			return list.get(0);
		}
		return null;
	}
}
